<div class="w600 cpos_1" style="margin-bottom:<?php echo empty($parent_id)?'70':'20' ?>px">  
  <?php
  if (!empty($parent_id)) {
    $categories = $this->category_model->get_all(array('parent_id' => $parent_id));
    foreach ($categories as $category) {
      $cat_promotions = $this->category_promotion_model->get_all(array('cat_id' => $category['id']));
      $promotion_id = array('id' => array(0));
      foreach ($cat_promotions as $cat_promotion) {
        $promotion_id['id'][] = $cat_promotion['promotion_id'];
      }
      $conditions = array('status' => PROMOTION_PUBLISH, 'start_date <= ' => time(), 'end_date >= ' => time(), 'remain > ' => 0);
      if (userdata('country_id'))
        $conditions['country_id'] = userdata('country_id');
      if (userdata('state_id'))
        $conditions['state_id'] = userdata('state_id');
      if (userdata('city_id'))
        $conditions['city_id'] = userdata('city_id');
      $num_promotion = $this->promotion_model->count($conditions, null, $promotion_id);
      ?>
      <a style="<?php echo isset($category_id) && $category_id == $category['id'] ? 'color:#E06704' : '' ?>"
         href="<?php echo site_url('index/category/' . $category['id'] . '/' . str_nice_name($category['name'])) ?>">
        <?php echo $category['name'] ?> (<?php echo $num_promotion ?>)</a> <span class="color_e06704">|</span>
        <?php
      }
    }
    ?>
</div>